package com.shop.cereshop.agent.controller.voucher;

import cn.hutool.http.server.HttpServerRequest;
import com.shop.cereshop.agent.page.user.CereAgentUserVO;
import com.shop.cereshop.agent.page.voucher.AgentVoucherTransactionVO;
import com.shop.cereshop.agent.page.voucher.VoucherConsumeTotalVO;
import com.shop.cereshop.agent.param.voucher.VoucherDTO;
import com.shop.cereshop.agent.service.voucher.AgentVoucherTransactionService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.common.PageParam;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RequestMapping("voucher/transaction")
@RestController
@Api(value = "AgentVoucherTransactionController",tags = "代理商代金券交易流水表")
public class AgentVoucherTransactionController {
    @Autowired
    private AgentVoucherTransactionService agentVoucherTransactionService;


    /**
     * 获取代金卷流水记录接口
     * @param voucherDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取代金卷流水记录接口")
    @PostMapping("/list")
    public Result<Page<AgentVoucherTransactionVO>> getInfo(@RequestBody VoucherDTO voucherDTO, HttpServletRequest request){
        CereAgentUserVO user  =(CereAgentUserVO)request.getAttribute("user");
        if (user == null){
            return new Result<>(CoReturnFormat.USER_NOT_LOGIN);
        }
        Page<AgentVoucherTransactionVO > agentVoucherTransaction = agentVoucherTransactionService.getAgentVoucherTransaction(voucherDTO);
        return Result.success(agentVoucherTransaction);
    }

    /**
     * 获取代金卷流水统计接口
     */
    @ApiOperation(value = "获取代金卷流水统计接口")
    @PostMapping("/consumption/total")
    public Result<VoucherConsumeTotalVO> getConsumptionTotal(VoucherDTO voucherDTO,HttpServletRequest request){
        CereAgentUserVO user  =(CereAgentUserVO)request.getAttribute("user");
        if (user == null){
            return new Result<>(CoReturnFormat.USER_NOT_LOGIN);
        }
        VoucherConsumeTotalVO consumptionTotal = agentVoucherTransactionService.getConsumptionTotal(voucherDTO);
        return Result.success(consumptionTotal);

    }
}
